import datetime

class Cat:
    def __init__(self, birthDate, catID, name=''):
        self._birthDate = datetime.datetime.strptime(birthDate, '%Y-%m-%d').date()
        self._name = name
        self._ID = catID

    def age(self):
        today = datetime.date.today()
        ageInDays = int((today - self._birthDate).days)
        return ageInDays

    def giveName(self, name):
        self._name = name

    def getBirthDate(self):
        return self._birthDate

    def getName(self):
        return self._name

    def getID(self):
        return self._ID

    def __eq__(self, other):
        return self.getID() == other.getID()



def addCat(catList):
    birthDate = input("Enter the cat's birthdate (YYYY-MM-DD): ")
    catID = int(input("Enter the cat's ID: "))
    name = input("Enter the cat's name: ")

    newCat = Cat(birthDate, catID, name)
    catList.append(newCat)

    print("add  successfully.")
    return catList


def removeCat(catList):
    IdRemove = int(input("Enter the ID of the cat to remove: "))
    for cat in catList:
        if cat.getID() == IdRemove:
            catList.remove(cat)
            return catList

    print("No cat found")
    return catList


def seeCats(catList):
    if not catList:
        print(" no cats")
    else:
        for cat in catList:
            print(f"ID: {cat.getID()}, Name: {cat.getName()}, Age: {cat.getBirthDate()} days")


def changeName(catList):
    IdChange = int(input("Enter the ID: "))
    for cat in catList:
        if cat.getID() == IdChange:
            name = input("Enter the new name for the cat: ")
            cat.giveName(name)
            return catList

    print(f"No cat found ")
    return catList


def checkDuplicates(catList):
    checkList = []
    for cat in catList:
        if cat.getID() not in checkList:
            checkList.append(cat.getID())
        else:
            print("True")
            return True

    print("False")
    return False

def uploadCatList():
    catList = []
    try:
        with open("catDB.txt", "r") as file:
            for line in file:
                data = line.strip().split(',')
                if len(data) == 3:
                    catList.append(Cat(data[1].strip(), data[0].strip(), data[2].strip()))
    except FileNotFoundError:
        pass  # File doesn't exist, returning an empty list
    return catList

def saveList(catList):
    with open("catDB.txt", "w") as file:
        for cat in catList:
            file.write(f"{cat.getID()}, {cat.getBirthDate()}, {cat.getName()}\n")
def menu():
    print("1.Exit: to leave the program")
    print("2.Save a cat: this option will call the function addCat")
    print("3.Adopt a cat: this option will call the function removeCat")
    print("4.See the cats: this option will call the function seeCats")
    print("5.Change a cat’s name: this option will call the function changeName")
    print("6.check")




# Example usage:
catList = []
stop = 0
while stop != 1:
    menu()
    option = int(input("please enter option "))
    if option == 1:
        stop = 1

    if option == 2:
        catList = addCat(catList)

    if option == 3:
        catList = removeCat(catList)

    if option == 4:
        seeCats(catList)

    if option == 5:
        catList = changeName(catList)

    if option == 6:
        checkDuplicates(catList)






